package com.daiqile.myinterest.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;

/**
 * @author Mr.Bean
 * @date Created on 2017/12/4.
 */

public class NewSrollView extends ScrollView{
    private int downX, downY;
    private int mTouchSlop;
    int currentY;
    public ObservableScrollView parentScrollView;

    public NewSrollView(Context context) {
        super(context);
    }

    public NewSrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NewSrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public NewSrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    private OnNewScrollViewScrollChanged mOnNewScrollViewScrollChanged;

    public void setOnNewScrollViewScrollChanged(OnNewScrollViewScrollChanged mOnNewScrollViewScrollChanged) {
        this.mOnNewScrollViewScrollChanged = mOnNewScrollViewScrollChanged;
    }

    public interface OnNewScrollViewScrollChanged{
        void onNewScrollViewScrollChanged(int l, int t, int oldl, int oldt);
    }

    /**
     * @param l Current horizontal scroll origin. 当前滑动的x轴距离
     * @param t Current vertical scroll origin. 当前滑动的y轴距离
     * @param oldl Previous horizontal scroll origin. 上一次滑动的x轴距离
     * @param oldt Previous vertical scroll origin. 上一次滑动的y轴距离
     */
    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if(mOnNewScrollViewScrollChanged!=null){
            mOnNewScrollViewScrollChanged.onNewScrollViewScrollChanged(l,t,oldl,oldt);
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        int action = ev.getAction();
        switch (action) {
            case MotionEvent.ACTION_DOWN://单点触摸

           /*     currentY = (int)ev.getY();
                downX = (int) ev.getRawX();
                downY = (int) ev.getRawY();
                Log.d("downY",String.valueOf(downY));*/
                break;
            case MotionEvent.ACTION_MOVE://触摸点移动

            /*    int moveY = (int) ev.getRawY();
                Log.d("moveY",String.valueOf(moveY));
                // 判断是否滑动，若滑动就拦截事件
                if (Math.abs(moveY - downY) > mTouchSlop) {
                    return false;
                }*/
                break;
            case MotionEvent.ACTION_CANCEL:

            default:
                break;
        }
        return super.onInterceptTouchEvent(ev);
    }

}
